﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace Water.Architecture2.EntityXML
{
    internal class EntityNode
    {
        private List<PropertyNode> propertyNodes = new List<PropertyNode>();

        internal List<PropertyNode> PropertyNodes
        {
            get { return propertyNodes; }
            set { propertyNodes = value; }
        }

        private string entityClass;

        internal string EntityClass
        {
            get { return entityClass; }
            set { entityClass = value; }
        }
        private string table;

        internal string Table
        {
            get { return table; }
            set { table = value; }
        }
        private string view;

        internal string View
        {
            get { return view; }
            set { view = value; }
        }

        private string sql;

        internal string Sql
        {
            get { return sql; }
            set { sql = value; }
        }
       
        private string defaultOrderByExpress;

        internal string DefaultOrderByExpress
        {
            get { return defaultOrderByExpress; }
            set { defaultOrderByExpress = value; }
        }

        private string connectionStringName;

        internal string ConnectionStringName
        {
            get { return connectionStringName; }
            set { connectionStringName = value; }
        }

        private bool queryOnly;

        internal bool QueryOnly
        {
            get {
                if (this.queryOnly)
                    return this.queryOnly;
                else {
                    return this.IsQueryOnly();
                }
            }
            set { queryOnly = value; }
        }

        private bool cache;

        internal bool Cache
        {
            get { return cache; }
            set { cache = value; }
        }

        private string dalClass;

        public string DalClass
        {
            get { return dalClass; }
            set { dalClass = value; }
        }
        private string dalAssembly;

        public string DalAssembly
        {
            get { return dalAssembly; }
            set { dalAssembly = value; }
        }

        private bool subquery=false;

        public bool Subquery
        {
            get { return subquery; }
            set { subquery = value; }
        }
        //private string assembly;

        //public string Assembly
        //{
        //    get { return assembly; }
        //    set { assembly = value; }
        //}

        /// <summary>
        /// 是否该实体仅支持查询(辅助方法)
        /// </summary>
        private bool IsQueryOnly()
        {
            
                if (!string.IsNullOrEmpty(this.table))
                    return false;
                else if (!string.IsNullOrEmpty(this.view) || !string.IsNullOrEmpty(this.sql))
                {
                    return true;
                }
                else
                    throw new Exception(string.Format(Water.Resources.Globalize.ExceptionResource.ExceptionEntityTableViewSqlNotfound, this, this.entityClass));
        }
    }
}
